package com.caul.demo.hadoop.mapreduce.rank;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.htrace.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * Created by sdliang on 2018/4/11.
 */
public class RankMapper extends Mapper<LongWritable, Text, RankKey, NullWritable> {

  ObjectMapper objectMapper;

  @Override
  protected void setup(Context context) throws IOException, InterruptedException {
    objectMapper = new ObjectMapper();
  }

  @Override
  protected void map(LongWritable key, Text value, Context context)
      throws IOException, InterruptedException {
    RankKey rankKey = objectMapper.readValue(value.toString(), RankKey.class);
    context.write(rankKey, NullWritable.get());
  }
}
